
#define _UNICODE
#include <wchar.h>
#include <time.h>
#include "YjlSet.h"
#include "YjlDef.h"

//#define DBG(fmt, ...) wprintf(L##fmt, ##__VA_ARGS__);
#define DBG(fmt, ...) do{}while(0)

unsigned long long GetDateTimeByU64(void)
{
	DBG("==%s, %d\n", __FUNCTION__, sizeof(time_t));
	
	return time(NULL);
}
unsigned int GetDateTimeByU32(void)
{
	DBG("==%s\n", __FUNCTION__);
	return time(NULL);
}

void ConvDateTime (U32 timeval, TIMESTAMP_STRUCT* st)
{
	DBG("==%s1, sizeof(time_t)=%d\n", __FUNCTION__, sizeof(time_t));
	struct tm *ptime;
	ptime = gmtime((const time_t*)&timeval);

	st->year   = ptime->tm_year + 1900;
	st->month  = ptime->tm_mon +1;
	st->day    = ptime->tm_mday;
	st->hour   = ptime->tm_hour;
	st->minute = ptime->tm_min;
	st->second = ptime->tm_sec; 
}

unsigned long long ConvDateTime(TIMESTAMP_STRUCT* st, U64 timeval)
{
	// it's called !!
	U64 ret = 0;
	
	struct tm timeinfo = {0};
	timeinfo.tm_year = st->year-1900;
	timeinfo.tm_mon = st->month-1;
	timeinfo.tm_mday = st->day;
	timeinfo.tm_hour = st->hour;
	timeinfo.tm_min = st->minute;
	timeinfo.tm_sec = st->second;

//	int fraction;

	ret = mktime ( &timeinfo );
	DBG("==%s2, %lld\n", __FUNCTION__, ret);
	return ret;
}


void GetTime(wchar_t* pstr)
{
	DBG("==%s\n", __FUNCTION__);
	
	sprintf ((char*)pstr, "%s", __TIME__);
}

FILE* wfopen(const wchar_t* wfname, const char* mode)
{
	char filename[256];
	wcstombs(filename, wfname, 256);
	return fopen(filename, mode);
}

void StringReplaceChar(wchar_t *str, wchar_t oldchr, wchar_t newchr)
{
	int i, len = wcslen(str);
	for(i=0;i<len;i++)
	{
		if(str[i] == oldchr)
		{
			str[i] = newchr;
		}
	}
	
} 